package asimes;

import java.util.Arrays;

public class Josephus {
    public static void main(String[] args) {
        int len = 150;
        int totalCount = len;
        int[] arr1 = new int[len];
        int[] arr2 = new int[len];
        for (int i = 0; i < len; i++) {
            arr1[i] = i + 1;
        }
        System.out.println(Arrays.toString(arr1));
        int index = 0;
        int tmpCount = 0;
        int lastNum = -1;
        while (totalCount >= 0) {
            if (arr2[index] == 0) {
                tmpCount++;
                if (tmpCount == 3) {
                    System.out.println(arr1[index]);
                    arr2[index] = 1;
                    tmpCount = 0;
                    totalCount--;
                    if (totalCount == 0) {
                        lastNum = arr1[index];
                        break;
                    }
                } else {
                    index++;
                }

            } else {
                index++;
            }
            if (index >= len) {
                index = index % len;
            }
        }
        System.out.println(lastNum);
    }
}
